@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        备案管理
        <small>商品备案</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/goodsEorder">备案管理</a></li>
        <li class="active">商品备案</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary ">
                <div class="box-body table-responsive">
                    <a href="{{route('admin.goodsEorder.create')}}" class="btn btn-success"><i class="icon glyphicon glyphicon-plus"></i>添加</a>

                    {!! Form::model(@$goodsEorderInfo,array('route' => 'admin.goodsEorder.index','method' => 'get','class'=>'form-search form-inline pull-right')) !!}
                    <div class="form-group">
                        {!! Form::text('goods_sn',$filter['goods_sn'],['class'=>'form-control','placeholder'=>'商品货号'])!!}
                    </div>
                    <div class="form-group">
                        {!! Form::text('batchNumbers',$filter['batchNumbers'],['class'=>'form-control','placeholder'=>'批次号'])!!}
                    </div>
                    <div class="form-group" style="margin-right: 15px;">
                        {!! Form::select('checkStatus',$checkStatus,@$_GET['checkStatus'],['class'=>'form-control','placeholder'=>'审核状态'])!!}
                    </div>

                    <button type="submit" class="btn btn-primary">搜索</button>
                    <button type="button" onclick="window.location.href='/admin/goodsEorder'" class="btn btn-default">重置</button>
                    {!! Form::close() !!}
                </div>
            </div><!-- end .box box-primary -->
            {{--{!! Form::model($activitys,array('route' => 'admin.goodsEorder.sort','class'=>'form-horizontal')) !!}--}}
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">商品备案</h3>

                    <div class="pull-right">
                        <a href="{{route('admin.goodsEorder.create')}}" type="button" class="btn btn-block"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>

                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">

                    <table class="table table-hover no-margin" style="min-width: 1440px;">
                        <tr>
                            {{--<th style="width:50px;">排序</th>--}}
                            <th style="width:80px;">商品ID</th>
                            <th>商品货号</th>
                            <th style="width:200px;">商品名称</th>
                            <th>商品规格型号</th>
                            <th>原产国(检)</th>
                            <th>原产国(关)</th>
                            <th>计量单位(检)</th>
                            <th>计量单位(关)</th>
                            <th>备案价格</th>
                            <th>币制（检）</th>
                            <th>币制（关）</th>
                            <th>商品描述</th>
                            <th>备案状态</th>
                            <th>操作</th>

                        </tr>

                        @foreach($goodsEorderInfo as $item)
                        <?php
                            $currencyCiqArr = config('goods-etouch-setting.currencyCiq');
                            $currencyCusArr = config('goods-etouch-setting.currencyCus');
                            $countryCiqArr = config('goods-etouch-setting.countryCiq');
                            $countryCusArr = config('goods-etouch-setting.countryCus');
                            $unitCiqArr = config('goods-etouch-setting.unitCiq');
                            $unitCusArr = config('goods-etouch-setting.unitCus');
                            if($item->currencyCiq){
                                $currencyCiq = @$currencyCiqArr[$item->currencyCiq];
                            }
                            if($item->currencyCus){
                                $currencyCus = @$currencyCusArr[$item->currencyCus];
                            }
                            if($item->originCountryCiq){
                                $originCountryCiq = @$countryCiqArr[$item->originCountryCiq];
                            }
                            if($item->originCountryCus){
                                $originCountryCus = @$countryCusArr[$item->originCountryCus];
                            }
                            if($item->unitCiq){
                                $unitCiq = @$unitCiqArr[$item->unitCiq];
                            }
                            if($item->unitCus){
                                $unitCus = @$unitCusArr[$item->unitCus];
                            }


                        ?>
                        <tr>
                            <td>{{$item->goods_id}}</td>
                            <td>{{$item->goods_sn}}</td>
                            <td>{{$item->goods_name}}</td>
                            <td>{{$item->goods_spec}}</td>
                            <td>{{@$originCountryCiq}}</td>
                            <td>{{@$originCountryCus}}</td>
                            <td>{{@$unitCiq}}</td>
                            <td>{{@$unitCus}}</td>
                            <td>{{$item->price}}</td>
                            <td>{{@$currencyCiq}}</td>
                            <td>{{@$currencyCus}}</td>
                            <td>{{$item->goods_desc}}</td>
                            <td width="5%" style="text-align: center" class="checkStatus" id="{{$item->goods_id}}" checkStatus="{{$item->checkStatus}}">@if($item->checkStatus==1)
                                    <i  class="glyphicon glyphicon-ok " style=" cursor: pointer;color: green;"></i>
                                @else
                                    <i  class="glyphicon glyphicon-remove " style=" cursor: pointer;color: red;"></i>
                                @endif
                            </td>
                            <td>
                            <a href="{{route('admin.goodsEorder.edit',$item->goods_id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                            <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$item->goods_id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>
                                <div id="modal{{$item->goods_id}}" class="modal fade">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title">删除警告:</h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>确认要删除备案商品[{{$item->goods_id}}]吗?</p>
                                            </div>
                                            <div class="modal-footer">

                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                <button itemid="{{$item->goods_id}}" class="btn  btn-danger01" >删除</button>


                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div><!-- /.modal -->
                            <!-- <a href="{{route('admin.goodsEorder.custom_search',$item->goods_sn)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 备案查询</a> -->
                            <button type="button" class="btn btn-primary btn-xs custom_search" data-url="{{route('admin.goodsEorder.custom_search',$item->goods_sn)}}"><i class="icon glyphicon glyphicon-search"></i> 备案查询</button>
                            <button type="button" class="btn btn-primary btn-xs query_stock" data-url="{{route('admin.goodsEorder.query_stock',$item->goods_sn)}}"><i class="icon glyphicon glyphicon-query-stock"></i> 库存查询</button>

                            </td>

                        </tr>

                        @endforeach

                    </table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <!-- 分页 -->
                    <div class="pull-right no-margin-pager">
                        {!! $goodsEorderInfo->render() !!}
                    </div>

                </div>
                <!-- /.box-footer -->
            </div>
            <!-- /.box -->
            {{--{!! Form::close()  !!}--}}

        </div>
    </div>



</section>
<!-- /.content -->

<div class="modal fade" id="customSearchModal" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">商品在海关备案信息</h4>
      </div>
      <div class="modal-body">
        <!-- <div class="row">
          <div class="col-md-4">.col-md-4</div>
          <div class="col-md-4 col-md-offset-4">.col-md-4 .col-md-offset-4</div>
        </div>
        <div class="row">
          <div class="col-md-3 col-md-offset-3">.col-md-3 .col-md-offset-3</div>
          <div class="col-md-2 col-md-offset-4">.col-md-2 .col-md-offset-4</div>
        </div>
        <div class="row">
          <div class="col-md-6 col-md-offset-3">.col-md-6 .col-md-offset-3</div>
        </div>
        <div class="row">
          <div class="col-sm-9">
            Level 1: .col-sm-9
            <div class="row">
              <div class="col-xs-8 col-sm-6">
                Level 2: .col-xs-8 .col-sm-6
              </div>
              <div class="col-xs-4 col-sm-6">
                Level 2: .col-xs-4 .col-sm-6
              </div>
            </div>
          </div>
        </div> -->
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div class="modal fade" id="queryStockModal" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">商品在公共仓库库存信息</h4>
      </div>
      <div class="modal-body">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
$('.checkStatus').on('click',function(){
        var el = $(this);
        var id = el.attr('id');

        var url = "{{route('admin.goodsEorder.toggleShow')}}";
        $.ajax({
            url:url+"/?id="+id,
            type:'get',
            dataType:'json',
            success:function(result){
                if(result.info){
                    console.log(result);
                    if(result.checkStatus==1){
                        el.find('.glyphicon').removeClass('glyphicon-remove');
                        el.find('.glyphicon').addClass('glyphicon-ok');
                        el.find('.glyphicon').css("color","green");

                    }else{
                        console.log(result);
                        el.find('.glyphicon').removeClass('glyphicon-ok');
                        el.find('.glyphicon').addClass('glyphicon-remove');
                        el.find('.glyphicon').css("color","red");

                    }

                }
            }
        });
    });

    $('.btn-danger01').on('click',function(e){
        e.preventDefault();
        var id = $(this).attr("itemid");
        //alert(id);
        if(!id) return false;
        $.ajax({
            url:'/admin/goodsEorder/'+id+"?"+Math.random(),
            type:'delete',
            data:{id:id,'_token':'{{csrf_token()}}'},
            dataType:"json",
            success:function(result){

                if(result.status==1){
                    $('#del_alert').modal();
                    $("#ok").hide();
                    $("#no").show();
                    $("#message_content").html(result.info);
                    window.location.reload();
                }else{
                    alert(result.message);
                    window.location.reload();
                }

            }

        });
    });


    $('.custom_search').on('click', function(argument) {
        var el = $(this);
        var id = el.attr('id');
        var url = el.data('url');

        $('#customSearchModal').find('.modal-body').empty();

        $.ajax({
            url:url,
            type:'get',
            dataType:'json',
            success:function(result){

                if(result.good_no){

                    $('#customSearchModal').modal('show');

                    var fieldObj = {
                                        "good_no":"货号",
                                        "item_no":"备案编号",
                                        "shelf_good_name_foreign":"上架品名（英文）",
                                        "shelf_good_name":"上架品名",
                                        "good_name":"品名",
                                        "good_model":"商品型号",
                                        "country":"商品原产国",
                                        "unit":"计量单位",
                                        "unit1":"法定第一单位",
                                        "unit2":"法定第二单位",
                                        "code_hs":"HS编码",
                                        "tax_code":"行邮税号",
                                        "status":"状态"
                                    };

                    var viewData = "";

                    viewData += "<table class='table table-hover no-margin'>";

                    $.each(result,function(index,value){

                        if (index!=="brands"){

                            // viewData += "<div class='row'><div class='col-md-8 col-md-offset-2'>";
                            viewData += "<tr><td></td><td style=''>";

                            switch(index){

                                case "good_no":
                                    viewData += fieldObj.good_no;
                                    break;

                                case "item_no":
                                    viewData += fieldObj.item_no;
                                    break;

                                case "shelf_good_name_foreign":
                                    viewData += fieldObj.shelf_good_name_foreign;
                                    break;

                                case "shelf_good_name":
                                    viewData += fieldObj.shelf_good_name;
                                    break;

                                case "good_name":
                                    viewData += fieldObj.good_name;
                                    break;

                                case "good_model":
                                    viewData += fieldObj.good_model;
                                    break;

                                case "country":
                                    viewData += fieldObj.country;
                                    break;

                                case "unit":
                                    viewData += fieldObj.unit;
                                    break;

                                case "unit1":
                                    viewData += fieldObj.unit1;
                                    break;

                                case "unit2":
                                    viewData += fieldObj.unit2;
                                    break;

                                case "code_hs":
                                    viewData += fieldObj.code_hs;
                                    break;

                                case "tax_code":
                                    viewData += fieldObj.tax_code;
                                    break;

                                case "status":
                                    viewData += fieldObj.status;
                                    break;
                            }
                            // viewData += "：" + value + "</div></div>";

                            if (index=="status") {

                                viewData += "</td><td>";

                                switch(value){

                                    case "0":
                                    viewData += "暂存";
                                    break;

                                    case "1":
                                    viewData += "申报";
                                    break;

                                    case "2":
                                    viewData += "审批通过";
                                    break;

                                    case "3":
                                    viewData += "退单";
                                    break;

                                    case "9":
                                    viewData += "其他";
                                    break;
                                }
                                viewData += "</td></tr>";

                            }else{

                                viewData += "</td><td>" + value + "</td></tr>";
                            }
                        }
                    });
                    viewData += "</table>";

                    $('#customSearchModal').find('.modal-body').append(viewData);

                    /*console.log('货号：'+result.good_no);
                    console.log('备案编号：'+result.item_no);
                    console.log('上架品名（英文）：'+result.shelf_good_name_foreign);
                    console.log('上架品名：'+result.shelf_good_name);
                    console.log('品名：'+result.good_name);
                    console.log('商品型号：'+result.good_model);
                    console.log('商品原产国：'+result.country);
                    console.log('计量单位：'+result.unit);
                    console.log('法定第一单位：'+result.unit1);
                    console.log('法定第二单位：'+result.unit2);
                    console.log('HS编码：'+result.code_hs);
                    console.log('行邮税号：'+result.tax_code);
                    console.log('状态：'+result.status);*/

                }
            }
        });
    });




    $('.query_stock').on('click', function(argument) {
        var el = $(this);
        var id = el.attr('id');
        var url = el.data('url');


        $('#queryStockModal').find('.modal-body').empty();

        $.ajax({
            url:url,
            type:'get',
            dataType:'json',
            success:function(result){

                if (result.List) {

                    var fieldObj = {
                                        "PALLETZONE":"仓库编号",
                                        "OWNER_NO":"货主编码",
                                        "OWNER_ARTICLE_NO":"货主商品编号",
                                        "ARTICLE_NAME":"商品名称",
                                        "ARTICLE_IDENTIFIER":"商品备案号",
                                        "STOCK_QTY":"可销数量"
                                    };

                    var viewData = "";

                    viewData += "<table class='table table-hover no-margin'>";

                    $('#queryStockModal').modal('show');

                    $.each(result.List,function(index,value){

                        if (index!=="brands"){

                            viewData += "<tr><td></td><td style=''>";

                            switch(index){

                                case "PALLETZONE":
                                    viewData += fieldObj.PALLETZONE;
                                    break;

                                case "OWNER_NO":
                                    viewData += fieldObj.OWNER_NO;
                                    break;

                                case "OWNER_ARTICLE_NO":
                                    viewData += fieldObj.OWNER_ARTICLE_NO;
                                    break;

                                case "ARTICLE_NAME":
                                    viewData += fieldObj.ARTICLE_NAME;
                                    break;

                                case "ARTICLE_IDENTIFIER":
                                    viewData += fieldObj.ARTICLE_IDENTIFIER;
                                    break;

                                case "STOCK_QTY":
                                    viewData += fieldObj.STOCK_QTY;
                                    break;

                            }


                            viewData += "</td><td>" + value + "</td></tr>";

                        }
                    });
                    viewData += "</table>";

                    $('#queryStockModal').find('.modal-body').append(viewData);
                    console.log(result.List);
                }else{
                    console.log('no number');
                }
            }
        });
    });

</script>

<script>
    $('.btn-danger').on('click',function(){
        console.log('11');
    });
</script>
@endsection